﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using MyFloridaHouse.DataAccess.Extensions;
using MyFloridaHouse.libSvDTO;

namespace MyFloridaHouse.DataAccess
{
    public partial class DAL_CensusData
    {

        /// <summary>
        /// Gets the shape uogIDs (same as regionIDs).
        /// </summary>
        /// <param name="iWkt">The iWKT (well known text).</param>
        /// <param name="iLayerID">The ilayerID.</param>
        /// <returns>List of <see cref="ShapeUogIDDTO"/></returns>
        /// <remarks>SPROC: usp_GetShapeUogIDs</remarks>
        public List<int> GetShapeUogIDs(string iWkt, int iLayerID)
        {
            List<int> itemList = new List<int>();

            //string storedProcedureName = "usp_GetShapeUogIDs";
            string storedProcedureName = "usp_tl10GetShapeUogIDs10";

            using (SqlConnection db = Connect())
            {
                SqlCommand StoredProcedureCommand = new SqlCommand(storedProcedureName, db);
                StoredProcedureCommand.CommandType = CommandType.StoredProcedure;
                SqlParameter dataPartIDParm = StoredProcedureCommand.Parameters.AddWithValue("wkt", iWkt);
                dataPartIDParm.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm2 = StoredProcedureCommand.Parameters.AddWithValue("layerID", iLayerID);
                dataPartIDParm2.Direction = ParameterDirection.Input;

                db.Open();
                using (SqlDataReader rdr = StoredProcedureCommand.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        itemList.Add((int)rdr["uogid"]);
                    }
                }
            }

            return itemList;
        }
    }
}
